<!--
* @author dumeng
文档列表
-->
<template>
  <div class="courseware-container">
    <el-collapse-transition>
      <div v-show="searchshow" class="courseware-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model="listQuery.subjectName" placeholder="请输入文档名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <div class="courseware-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="courseware-search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="courseware-search separate">
        <div class="courseware-search-inner">
          <el-row>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">文档名称</div>
                <el-input v-model.trim="search.subjectName" style="width: 80%;" class="filter-item" placeholder="请输入文档名称搜索" />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">文档分类</div>
                <el-cascader
                  ref="classify"
                  v-model="search.subjectClassify"
                  style="width:80%"
                  clearable
                  :props="classifyProps"
                  :options="classifyOptions"
                />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">文档类型</div>
                <!--                <el-radio-group v-model="search.fileType" style="width: 80%;margin-top: 20px;">
                  <el-radio label="">全部</el-radio>
                  <el-radio label="WJLX_PDF">pdf文档</el-radio>
                  <el-radio label="WJLX_ANY">ANY文档</el-radio>
                  <el-radio label="WJLX_WORD">word文档</el-radio>
                  <el-radio label="WJLX_TXT">txt文档</el-radio>
                  <el-radio label="WJLX_PPT">PPT文档</el-radio>
                  <el-radio label="WJLX_EXCEL">EXCEL文档</el-radio>
                </el-radio-group>-->

                <el-select v-model="search.fileType" style="width: 80%" placeholder="请选择">
                  <el-option v-for="item in dict.WJLX" :key="item.dictValue" :label="item.dictName" :value="item.dictValue" />
                </el-select>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <!-- <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">关键词</div>
                <el-input
                  v-model.trim="search.subjectKeyword"
                  style="width: 80%;"
                  class="filter-item"
                  placeholder="请输入关键词搜索"
                />
              </div>
            </el-col> -->
          </el-row>
        </div>
        <div class="courseware-search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="courseware-search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </div>
      </div>
    </el-collapse-transition>
    <div v-if="!isSelect" class="courseware-btn">
      <div class="btn-title">
        <span>文档管理</span>
      </div>
      <div class="btn-btns">
        <el-button style="margin-left: 10px" @click="handleSetting">批量设置</el-button>
        <el-button style="margin-left: 10px;" @click=";(coursewareInfo = {}), (isCreate = true)">新建文档 </el-button>
        <el-button style="margin-left: 10px;" @click="handleSelectPlatform">选取SaaS平台文档 </el-button>
        <el-button v-if="activeTab === '2'" style="margin-left: 10px;" @click="handleSelectDelet">批量删除 </el-button>
        <el-button v-if="activeTab === '2'" style="margin-left: 10px;" @click="handleSelectSend">批量发布 </el-button>
      </div>
    </div>
    <div v-if="!isSelect" class="classify-tab">
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in statusOptions" :key="item.id" :label="item.statusName" :name="item.id" />
      </el-tabs>
    </div>
    <div class="courseware-list">
      <v-table
        ref="tabs"
        :list="courseList"
        :tag="activeTab === '3' ? 'documentLibraryLibrarRelease' : 'documentLibraryLibrar'"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :source-arr="sourceArr"
        @handleSelectionChange="handleSelectionChange"
      >
        <el-table-column prop="transcodeStatusValue" label="转码状态">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.transcodeFailReason ? scope.row.transcodeFailReason : scope.row.transcodeStatusValue"
              placement="top-start"
            >
              <span v-if="scope.row.transcodeStatus === '4'" style="color: red;"> {{ scope.row.transcodeStatusValue }}</span>
              <span v-else>{{ scope.row.transcodeStatusValue }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column v-if="!isSelect" fixed="right" label="操作" width="130">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleSee(scope.row)">查看</el-button>
            <template v-if="scope.row.transcodeStatus === '3' && scope.row.isForce !== 'SF01' ">
              <el-button v-if="scope.row.isForce !='SF01'" type="text" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
              <el-button v-if="scope.row.isForce !='SF01'" type="text" size="mini" @click="handlePublish(scope.row)">
                {{ scope.row.status === 'KCZT02' ? '发布' : '取消发布' }}
              </el-button>
              <!-- <el-button v-if="scope.row.status === 'KCZT01'" type="text" size="small" @click="handleCourse(scope.row)">创建课程</el-button>
              <el-button type="text" size="small" @click="handleExercises(scope.row)">练习题</el-button> -->
            </template>
            <el-button
              v-if="scope.row.status !== 'KCZT01' && scope.row.transcodeStatus !== '2' && scope.row.isForce !== 'SF01'"
              type="text"
              size="small"
              @click="handleDel(scope.row)"
            >删除</el-button>
            <el-button v-if="scope.row.transcodeStatus === '2'" type="text" size="small" @click="refresh(scope.$index, scope.row)">刷新</el-button>
            <el-button v-if="scope.row.transcodeStatus === '4' && scope.row.isForce !== 'SF01'" type="text" size="small" @click="handleAgain(scope.row)">重新转码</el-button>
            <el-button type="text" size="small" @click="handleShow(scope.row)">
              链接
            </el-button>
            <!-- 如果是转码中，只有查看-->
            <el-button
              v-if="scope.row.transcodeStatus !== '2' && scope.row.isForce !== 'SF01'"
              size="small"
              type="text"
              @click="handleDonwloadTwo(scope.row)"
            >
              下载</el-button>
          </template>
        </el-table-column>
      </v-table>
    </div>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <!--    -->
    <el-dialog
      v-if="preview.state"
      v-el-drag-dialog
      :visible.sync="preview.state"
      :close-on-click-modal="false"
      :fullscreen="isFull"
      title="预览"
      center
      width="600px"
      @close="preview.stat = false"
    >
      <span slot="title" class="my-title">
        <span>预览</span>
        <div class="full">
          <el-button size="small" type="primary" icon="el-icon-full-screen" @click="isFull = !isFull">{{ isFull ? '取消全屏' : '全屏' }}</el-button>
        </div>
      </span>
      <courseware-preview
        v-if="preview.state"
        :is-full="isFull"
        :type="preview.fileType"
        :show-type="preview.showType"
        :file-id="preview.fileId"
        style="width:100%;height:100%;"
      />
    </el-dialog>
    <create-courseware v-if="isCreate" :info="coursewareInfo" @close="closeFun" />
    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :destroy-on-close="true" :visible.sync="visibleState" title="查看" center width="800px">
      <el-row class="see-dialog">
        <el-col :span="12">
          <div class="box">
            <div class="key">文档封面：</div>
            <div class="value">
              <!-- <el-image :src="`/API-DOCUMENT/document/file/download?id=${coursewareInfo.subjectImg}`" fit="contain" /> -->
              <el-image
                style="width: 100px; height:auto;display: inline-block;vertical-align: top;"
                :src="isOss ? coursewareInfo.subjectImgUrl : view + coursewareInfo.subjectImg"
                :preview-src-list="[isOss ? coursewareInfo.subjectImgUrl : view + coursewareInfo.subjectImg]"
              >
                <div
                  slot="error"
                  class="image-slot"
                  style="width: 100%; height: 67px;background-color: #f8f8f8;display: flex;align-items: center;justify-content: center;"
                >
                  未上传
                </div>
              </el-image>
            </div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key min">文档：</div>
            <div class="value">
              <!-- 如果是转码中，只有查看-->
              <el-button
                v-if="coursewareInfo.fileType !== 'KCLX02' || coursewareInfo.transcodeStatus === '2'"
                size="small"
                type="primary"
                icon="el-icon-view"
                @click="handleDonwload(coursewareInfo)"
              >
                下载</el-button>
              <el-button
                v-if="coursewareInfo.transcodeStatus !== '2' && coursewareInfo.transcodeStatus !== '4' && coursewareInfo.fileType !== 'WJLX_ANY'"
                size="small"
                type="primary"
                icon="el-icon-view"
                @click="handlePreview(coursewareInfo, 'after')"
              >{{ coursewareInfo.fileType != 'KCLX02' ? '转码后' : '查看' }}</el-button>
            </div>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="box">
            <div class="key">文档名称：</div>
            <div class="value">{{ coursewareInfo.subjectName + '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">文档分类：</div>
            <div class="value">{{ coursewareInfo.subjectClassifyIdsValue || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">文档类型：</div>
            <div class="value">{{ coursewareInfo.fileTypeName || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key max">是否允许下载：</div>
            <div class="value">{{ coursewareInfo.isDownAttachment == '1' ?'允许下载' :'不允许下载' || '' }}</div>
          </div>
        </el-col>
        <el-col v-if="coursewareInfo.fileType === 'WJLX_PDF'" :span="12">
          <div class="box">
            <div class="key">PDF页数：</div>
            <div class="value">{{ fomatterTimeAndPage(coursewareInfo.fileType, coursewareInfo.subjectDuration) || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key">文档来源：</div>
            <div class="value">{{ coursewareInfo.subjectSource || '' }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key max">文档转码状态：</div>
            <div class="value">{{ coursewareInfo.transcodeStatusValue }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="box">
            <div class="key max">文档发布状态：</div>
            <div class="value">{{ coursewareInfo.statusValue }}</div>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="box">
            <div class="key">关键词：</div>
            <div class="value">{{ coursewareInfo.subjectKeyword || '' }}</div>
          </div>
        </el-col>
        <el-col :span="24">
          <div class="box">
            <div class="key min">标签：</div>
            <div class="value">
              {{ coursewareInfo.subjectLabel || '' }}
            </div>
          </div>
        </el-col>
        <el-col :span="24" style="white-space: pre-line;">
          <div class="box">
            <div class="key">简介：</div>
            <div v-if="coursewareInfo.subjectIntroduce" class="value textarea-view">{{ coursewareInfo.subjectIntroduce }}</div>
          </div>
        </el-col>
      </el-row>
      <section slot="footer" class="dialog-footer">
        <el-button style="padding: 10px 30px;" @click="visibleState = false">关 闭</el-button>
      </section>
    </el-dialog>
    <!-- 复制链接 -->
    <el-dialog title="链接地址" :visible.sync="dialogVisible1" width="55%">
      <div class="btns">
        <el-button type="primary" @click="copyUrl('oss')">复制OSS地址</el-button>
        <div class="local" />
        <el-button type="primary" @click="copyUrl('doc')">复制本地地址</el-button>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
      </span>
    </el-dialog>
    <!--批量设置-->
    <el-dialog
      v-el-drag-dialog
      title="批量设置"
      :visible.sync="batchSettingDialog"
      center
      :close-on-click-modal="false"
      destroy-on-close
      @closed="clearSettingForm"
    >
      <section class="main-table">
        <el-form ref="form" :rules="rules" label-width="120px" class="form">
          <el-form-item label="批量命名">
            <el-input v-model.trim="name" maxlength="100" placeholder="请输入图片名称" />
          </el-form-item>
          <el-form-item label="起始编号">
            <el-input v-model.trim="startNumber" maxlength="100" placeholder="请输入编号" />
          </el-form-item>
          <el-form-item label="转移至分类下" prop="classifyId">
            <el-cascader
              ref="classify"
              v-model="curriculumClassify"
              style="width:100%"
              clearable
              :props="classifyProps"
              :options="classifyOptions"
            />
          </el-form-item>
        </el-form>
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="clearSettingForm">取消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="handleBatchSetting()">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { deleteSubject, fetchList, getClassifyTree, update, get, batchPublish, batchDelet, batchSetting, getDictByCode } from '../api/videoLibrary'
import { mapGetters } from 'vuex'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
import CoursewarePreview from '../components/CoursewarePreview'
import CreateCourseware from '../components/createCourseware'
import vTable from '@/components/Table'
export default {
  name: 'VideoLibrary',
  components: { Pagination, CoursewarePreview, CreateCourseware, vTable },
  directives: { elDragDialog },
  props: {
    isSelect: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isFull: false, // 是否全屏
      listLoading: false,
      list: null,
      total: 0,
      searchshow: true,
      search: {
        subjectName: '',
        subjectClassify: '',
        subjectKeyword: '',
        subjectSource: '',
        subjectType: 'KCLX02',
        fileType: '' // 固定课程类型为文档
      },
      classifyProps: {
        label: 'classifyName',
        value: 'id',
        checkStrictly: true
      },
      classifyOptions: [],
      statusOptions: [
        {
          statusName: '全部',
          id: '1'
        },
        {
          statusName: '未发布',
          id: '2'
        },
        {
          statusName: '已发布',
          id: '3'
        }
      ],
      activeTab: '1',
      listQuery: {
        page: 1,
        limit: 10,
        subjectName: '',
        subjectType: 'KCLX02'
      },
      checkList: [],
      courseList: [],
      view: '/API-DOCUMENT/document/file/download?id=',
      dict: {
        WJLX: [] // 文档类型
      },
      preview: {
        fileId: '',
        fileType: '',
        showType: '',
        state: false
      },
      coursewareInfo: {},
      visibleState: false,
      multipleSelection: [],
      isCreate: false,
      isOss: sessionStorage.getItem('FILE_SAVE_THIRD_CONFIG') || false,
      sourceArr: ['subjectImgUrl'],
      isCreatePage: true,
      dialogVisible1: false,
      selectFrom: {},
      // 批量设置
      subjectClassify: '',
      batchSettingDialog: false,
      name: '',
      startNumber: '',
      subjectName: '',
      startNum: '',
      curriculumClassify: [],
      rules: {}
    }
  },
  computed: {
    ...mapGetters(['sidebar'])
  },
  created() {
    this.activeTab = this.$route.query.active || '1'
    for (const key in this.dict) {
      this.getDict(key)
    }
    this.getClassifyOption()
    this.getList()
  },
  // activated() {
  //   if (this.isCreatePage) { this.listQuery.page = 1 }
  //   this.getList()
  // },
  methods: {
    /**
     * 获取字典
     */
    getDict(code) {
      return new Promise((resolve, reject) => {
        getDictByCode(code).then(res => {
          this.dict[code] = (res.data.data && res.data.data.length > 0) ? res.data.data[0].list : []
        }).catch(error => {
          reject(error)
        })
      })
    },
    handleDonwloadTwo(ite) {
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = '/API-DOCUMENT/document/file/download?id=' + ite.courseId
      link.setAttribute('download', ite.subjectName)
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    /**
     *多选
     */
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    /**
     * 批量设置图片名称和图片分类
     */
    async handleSetting() {
      this.batchSettingDialog = true
      this.curriculumClassify = []
      await this.getClassifyOption()
    },
    // 清除批量设置内容
    clearSettingForm() {
      this.name = ''
      this.startNumber = ''
      this.batchSettingDialog = false
      this.curriculumClassify = []
    },
    /**
     * 批量设置名称、分类
     */
    handleBatchSetting() {
      return new Promise((resolve, reject) => {
        if (this.multipleSelection.length > 0) {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          const params = {
            id: this.multipleSelection.map(item => {
              return item.id
            }).join(','),
            subjectName: this.name,
            startNum: this.startNumber,
            subjectClassify: this.curriculumClassify[this.curriculumClassify.length - 1]
          }
          batchSetting(params)
            .then((res) => {
              this.dialogVisible = false
              loading.close()
              this.$message({
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
              this.clearSettingForm()
              this.getList()
              this.$refs.tabs.handleChangeSelection(this.multipleSelection)
            }).catch((error) => {
              reject(error)
              loading.close()
            })
        } else {
          this.$message({
            type: 'warning',
            message: '请选择需要修改的文档'
          })
        }
      })
    },
    handleSelectPlatform() {
      this.$router.push({ path: '/contentRepository/documentLibrary/SelectCourse4platform', query: {}})
    },
    refresh(index, row) {
      this.getData(row.id).then((res) => {
        if (res !== 0) {
          this.$set(this.courseList, index, res)
        }
      })
    },
    getData(id) {
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      return new Promise((resolve, reject) => {
        get({ id: id })
          .then((res) => {
            loading.close()
            resolve(res.data.data)
          })
          .catch((e) => {
            loading.close()
            resolve(0)
          })
      })
    },
    /**
     * 格式化文档时长单位
     */
    fomatterTimeAndPage(type, t) {
      if (type === 'WJLX_PDF') {
        return t + '页'
      } else {
        const fTime = t || 0
        let time = parseInt(fTime) + '秒'
        if (parseInt(fTime) > 60) {
          var second = parseInt(fTime) % 60
          var min = parseInt(fTime / 60)
          time = min + '分' + second + '秒'

          if (min > 60) {
            min = parseInt(fTime / 60) % 60
            var hour = parseInt(parseInt(fTime / 60) / 60)
            time = hour + '小时' + min + '分' + second + '秒'

            if (hour > 24) {
              hour = parseInt(parseInt(fTime / 60) / 60) % 24
              var day = parseInt(parseInt(parseInt(fTime / 60) / 60) / 24)
              time = day + '天' + hour + '小时' + min + '分' + second + '秒'
            }
          }
        }
        return time
      }
    },
    /**
     * 转换成数组
     */
    getArr(str) {
      try {
        return str.split(',')
      } catch (e) {
        return []
      }
    },
    /**
     * 创建课程
     */
    handleCourse(item) {
      this.isCreatePage = false
      this.$router.push({ path: this.$filterPath('create'), query: { i: item.id, t: 'courseware', active: this.activeTab }})
    },
    closeFun() {
      this.isCreate = false
      this.getList()
    },
    /**
     * 选项卡切换
     */
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      this.getList()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      this.$emit('handleSelect', this.multipleSelection)
    },
    /**
     * 预览
     * i: 文档信息
     */
    handlePreview(i, t) {
      this.preview.fileId = t === 'before' ? i.courseId : i.courseIdUrl
      this.preview.fileType = i.fileType
      this.preview.showType = t
      this.preview.state = true
    },
    handleDonwload(item) {
      console.log(item, '------------------------')
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = '/API-DOCUMENT/document/file/download?id=' + item.courseId
      link.setAttribute('download', item.subjectName)
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    /**
     * 查看
     * i: 文档信息
     */
    handleSee(i) {
      this.coursewareInfo = i
      this.visibleState = true
    },
    /**
     * 重新转码
     * i: 文档信息
     */
    handleAgain(i) {
      this.coursewareInfo = i
      this.isCreate = true
    },
    /**
     * 练习题
     */
    handleExercises(item) {
      this.$router.push({ path: this.$filterPath('exercises'), query: { ci: item.id, active: this.activeTab }})
    },
    /**
     * 启用/禁用
     */
    handlePublish(row) {
      const state = row.status === 'KCZT01' ? 'KCZT02' : 'KCZT01'
      let msg = ''
      if (row.status === 'KCZT01') {
        msg = '取消发布'
      } else {
        msg = '发布'
      }
      this.$confirm('确定' + msg + '该文档吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            update({ id: row.id, status: state })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '操作成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {})
    },
    /**
     * 获取文档分类
     */
    getClassifyOption() {
      return new Promise((resolve, reject) => {
        getClassifyTree({ classifyType: 'JNZQFL07' })
          .then(({ data }) => {
            this.classifyOptions = data.data || []
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    getList(obj) {
      this.listLoading = true

      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      if (this.activeTab === '1') {
        query['status'] = ''
      } else if (this.activeTab === '3') {
        query['status'] = 'KCZT01'
      } else {
        query['status'] = 'KCZT02'
      }
      if (this.searchshow) {
        query['subjectName'] = this.listQuery.subjectName
        query['subjectType'] = this.listQuery.subjectType
      } else {
        query['subjectName'] = this.search.subjectName
        query['subjectClassify'] = this.search.subjectClassify.length > 0 ? this.search.subjectClassify[this.search.subjectClassify.length - 1] : ''
        query['subjectKeyword'] = this.search.subjectKeyword
        query['subjectSource'] = this.search.subjectSource
        query['subjectType'] = this.search.subjectType
        query['fileType'] = this.search.fileType
      }
      return new Promise((resolve, reject) => {
        fetchList(query)
          .then((response) => {
            this.courseList = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            this.listLoading = false
            reject(error)
          })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.subjectName = ''
      for (const i in this.search) {
        this.search['' + i + ''] = ''
      }
      this.search.subjectType = 'KCLX02'
      this.listQuery.page = 1
      this.getList()
    },
    handleUpdate(item) {
      this.isCreatePage = false
      this.$router.push({ path: this.$filterPath('documentLibraryManage'), query: { i: item.id, type: 'u', active: this.activeTab }})
    },
    handleDeletes() {
      const arr = []
      if (this.checkList.length > 0) {
        this.checkList.forEach((item) => {
          arr.push(item)
        })
        var ids = arr.join(',')
        this.deleteSubject(ids)
      } else {
        this.$message({
          message: '请选择需要删除的数据！',
          type: 'error'
        })
      }
    },
    handleDel(row) {
      if (row.status === 'KCZT01') {
        this.$message({
          message: '文档已发布，无法删除',
          type: 'warning'
        })
      } else {
        this.deleteSubject(row.id)
      }
    },
    deleteSubject(ids) {
      this.$confirm('此操作将永久删除该文档, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            deleteSubject({ id: ids })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '删除成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    filtercolumn(scope, item) {
      return scope.row[item]
    },
    handleSelectDelet() {
      if (this.multipleSelection.length > 0) {
        this.$confirm('此操作将永久删除选中文档, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            const loading = this.$loading({
              lock: true,
              text: '请稍后',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.3)'
            })
            const params = {
              ids: this.multipleSelection.map((i) => i.id).join(',')
            }
            batchDelet(params)
              .then((res) => {
                loading.close()
                this.getList()
              })
              .catch((err) => loading.close(err))
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择需要删除的文档'
        })
      }
    },
    handleSelectSend() {
      if (this.multipleSelection.length > 0) {
        const loading = this.$loading({
          lock: true,
          text: '请稍后',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.3)'
        })
        const params = {
          id: this.multipleSelection.map((i) => i.id).join(','),
          status: 'KCZT01'
        }
        batchPublish(params)
          .then((res) => {
            loading.close()
            this.getList()
          })
          .catch((err) => loading.close(err))
      } else {
        this.$message({
          type: 'warning',
          message: '请选择需要发布的文档'
        })
      }
    },

    handleShow(row) {
      this.selectFrom = row
      this.dialogVisible1 = true
    },
    /**
     * 复制地址
     */
    copyUrl(type) {
      const ths = this
      this.$copyText(this.getUrl(ths.selectFrom, type)).then(
        function(e) {
          ths.$message.success('复制成功')
        },
        function(e) {
          ths.$message.error('复制失败，请手动复制')
        }
      )
    },
    /**
     * 获取文档地址
     */
    getUrl(row, tpye) {
      // return this.view + row.imgId
      if (tpye === 'oss') {
        return row.courseIdUrl
      } else {
        return this.view + row.courseId
      }
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.el-dialog .el-dialog__footer {
  text-align: center;
}
$dark_gray: #bfced6;
.courseware-container {
  padding: 20px;
  .el-button + .el-button {
    margin-left: 0 !important;
  }
  .my-title {
    width: 100%;
    display: inline-block;
    font-size: 16px !important;
    font-family: PingFangSC-Medium !important;
    font-weight: 700 !important;
    color: #333333 !important;
    position: relative;
    .full {
      position: absolute;
      width: 100px;
      height: 58px;
      right: 50px;
      top: -18px;
      display: flex;
      align-items: center;
      text-align: right;
    }
  }
  .courseware-search {
    background-color: #fff;
    padding: 0 20px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;

      &_login {
        font-size: 20px;
      }
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .courseware-search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .courseware-search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .courseware-search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .courseware-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;

    .el-tabs__nav-wrap::after {
      display: none;
    }

    .el-tabs__header {
      margin: 0;
    }
  }

  .courseware-btn {
    display: flex;
    height: 46px;
    line-height: 46px;
    width: 100%;

    .btn-title {
      flex: 1;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .courseware-list {
    background-color: white;
    margin-top: 10px;
    padding: 10px;
    .el-image {
      width: 100%;
      height: auto;
      max-height: 60px;
      .image-slot {
        width: 100%;
        height: 67px;
        background-color: #f8f8f8;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    .el-form-item {
      margin-bottom: 5px;
    }

    .el-dropdown-link {
      cursor: pointer;
      @include font-color($mainColor);
    }
  }

  .pagination-container {
    background: none;
  }
  .el-row.see-dialog {
    height: 500px;
    overflow-y: auto;
    padding: 5px 40px;
    .box {
      display: flex;
      width: 100%;
      min-height: 38px;
      .key {
        width: 70px;
        &.max {
          width: 100px;
        }
        &.min {
          width: 50px;
        }
      }
      .value {
        flex: 1;
        color: #333;
        font-weight: 500;
        padding-right: 30px;

        &.textarea-view {
          white-space: pre-line;
          border: 1px solid #e5e5e5;
          border-radius: 6px;
          padding: 10px;
          color: #333;
          background-color: #f9f9f9;
          font-weight: normal;
        }
      }
    }
    .el-col {
      padding-top: 10px;
      margin-top: 15px;
    }
  }
  .cell {
    .el-image {
      width: 100%;
    }
  }
  .btns {
    display: flex;
    justify-content: center;
    padding: 10px;
    .local {
      margin-left: 10px;
    }
  }
}
</style>
